/*
 * solver.cpp
 *
 *  Created on: 2011-08-22
 *      Author: Graham
 */

#include <string>
#include <iostream>
#include "solver.h"

using namespace std;

Solver::Solver(Dictionary* d1)
//Assigns passed dictionary pointer to internal handle
{
	if (d1!=NULL) //Verify that the dictionary instance exists
	{
		dict=d1; //Assigns passed dictionary pointer to internal handle
	}
	else
	{
		throw SolverException("Dictionary import Failed");
	}
}

int Solver::solve(Key* k1, Cipher* c1)
//Function to import user Key and a Cipher, subdivide the cipher into words, and initate the solver class using whatever algorithm seems appropriate.
//Returns integer indicating percentage of words in list matched, or -1 indicating that no satisfactory key could be found, and the value in Solver::bestKey is just the last one generated (or best candidate?).
{
	bool solved=false; //initialize return value
	
	if ((k1!=NULL) && (c1!=NULL)) //check input pointers
	{
		userKey=k1&; //I'm pretty sure this will generate an error, but I want a separate instance of the class
		divideCipher(c1);
	}
	else
	{
		throw SolverException("Key or cipher import Failed");
	}

	//attempt to solve stuff
	
	return solved;
}

void Solver::divideCipher(Cipher* c1)
//Function which takes the cipher argument, and divides the cipher text into words, populating the `wordList`
{
	//go through c1.getString, looking for spaces, and building the word stack? heap? from the space-delimited words
}

int Solver::recursiveSolve(Key*, char**)
//Function which takes the user supplied key, and the word list, and brute forces the gaps based on each word in the list, sequentially.
//Returns integer indicating success or failure
{
}

SolverException::SolverException(const string& m) : message(m) {}

string& SolverException::getMessage(){
	return message;
}
